﻿Imports System.Data
Imports System.Runtime.CompilerServices

Partial Class KYC_frmShowDetail
    Inherits System.Web.UI.Page
    Dim ds As DataSet
    Dim sanctionAll As ADOEntitySanctionList.SanctionListEntities

    Const SEP As String = "/"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            sanctionAll = New ADOEntitySanctionList.SanctionListEntities
            ds = Session("ds")

            bindData()

            'txtComment1.Text = ds.Tables("Result").Rows(strRowIndex).Item("comment1")
            'txtComment2.Text = ds.Tables("Result").Rows(strRowIndex).Item("comment2")

        Catch ex As Exception

        End Try


    End Sub


    Private Sub bindData()

        Dim strRowIndex As String = Request.QueryString("RowIndexDetail")

        Try
            Dim rowDetail = ds.Tables("Result").Rows(strRowIndex)

            Dim entity_id = rowDetail.Item("ENTITY_ID").ToString

            tbDataSource.Text = rowDetail.Item("dataSource")
            tbEntID.Text = entity_id
            tbLastUpdate.Text = rowDetail.Item("LastUpdateDate")
            tbListName.Text = rowDetail.Item("listtypecode")
            tbListDesc.Text = rowDetail.Item("listtypename")

            bindName(entity_id, rowDetail)
            bindIDNumber(entity_id, rowDetail)
            bindDOB(entity_id)
            bindNationality(entity_id)
            bindProfileComment(entity_id)
           
        Catch ex As Exception

        End Try
    End Sub

    Sub bindName(ByVal entity_id As String, ByVal rowDetail As DataRow)
        Dim listName = (From n In sanctionAll.AMLO_NEW_NAME_TEMP
                           Where n.ENTITY_ID = entity_id And
                           (n.SINGLE_STRING_NAME IsNot Nothing Or n.ORIGINAL_SCRIPT_NAME IsNot Nothing)
                           Select n.SINGLE_STRING_NAME, n.ORIGINAL_SCRIPT_NAME).ToList

        Dim nameStringComplete = ""
        Dim nameFirst = ""

        'Ball V-Smart
        '=== Append *** to name that matched with gridview clicked row ===
        For i = 0 To listName.Count - 1

            Dim singleName = listName(i).SINGLE_STRING_NAME
            Dim originalName = listName(i).ORIGINAL_SCRIPT_NAME
            If Not String.IsNullOrEmpty(singleName) Then
                If singleName.Equals(rowDetail("FULLNAME").ToString) Then
                    nameFirst = "***" & singleName & "***" & Environment.NewLine
                Else
                    nameStringComplete += singleName & Environment.NewLine
                End If

            End If

            If Not String.IsNullOrEmpty(originalName) Then
                If originalName.Equals(rowDetail("ORIGINAL_SCRIPT_NAME").ToString) Then
                    nameFirst = "***" & originalName & "***" & Environment.NewLine
                Else
                    nameStringComplete += originalName & Environment.NewLine
                End If
            End If

        Next
        If Not String.IsNullOrEmpty(nameStringComplete) Or Not String.IsNullOrEmpty(nameFirst) Then
            tbNames.Text = nameFirst & nameStringComplete
        End If
    End Sub

    Sub bindIDNumber(ByVal entityID As String, ByVal rowDetail As DataRow)
        Dim listID = (From i In sanctionAll.AMLO_NEW_IDNUMBER_TEMP
                          Where i.ENTITY_ID = entityID And
                            i.ID_VALUE IsNot Nothing
                            Select i.ID_VALUE).ToList

        Dim strIDFirst = ""
        Dim strIDComplete = ""

        'Ball V-Smart
        '=== Append *** to UniqueID that matched with gridview clicked row ===
        For i = 0 To listID.Count - 1
            Dim idVal = listID(i).ToString

            If Not String.IsNullOrEmpty(idVal) Then
                If idVal.Equals(rowDetail("UniqueID").ToString) Then
                    strIDFirst = "***" & idVal & "***" & Environment.NewLine
                Else
                    strIDComplete += idVal & Environment.NewLine
                End If

            End If
        Next

        If Not String.IsNullOrEmpty(strIDFirst) Or Not String.IsNullOrEmpty(strIDComplete) Then
            tbIDNumber.Text = strIDFirst & strIDComplete
        End If

    End Sub

    Sub bindDOB(ByVal entityID As String)
        Dim listID = (From b In sanctionAll.AMLO_NEW_BIRTHINFO_TEMP
                          Where b.ENTITY_ID = entityID And
                           b.BIRTHINFO_DATE IsNot Nothing
                            Select b.BIRTHINFO_DATE).ToList

        Dim strDOBComplete = ""
        For x = 0 To listID.Count - 1
            strDOBComplete += listID(x).ToString & Environment.NewLine
        Next

        If Not String.IsNullOrEmpty(strDOBComplete) Then
            tbDOB.Text = strDOBComplete
        End If

    End Sub

    Sub bindNationality(ByVal entityID As String)
        Dim listNation = (From b In sanctionAll.AMLO_NEW_RESIDENT_TEMP
                          Where b.ENTITY_ID = entityID And
                           b.COUNTRY_DESC IsNot Nothing
                            Select b.COUNTRY_DESC).ToList

        Dim strNationComplete = ""
        For x = 0 To listNation.Count - 1
            strNationComplete += listNation(x).ToString & Environment.NewLine
        Next

        If Not String.IsNullOrEmpty(strNationComplete) Then
            tbNation.Text = strNationComplete
        End If

    End Sub

    Sub bindProfileComment(ByVal entity_id As String)
        Dim profileNote = (From m In sanctionAll.AMLO_NEW_MASTER_TEMP
                         Where m.ENTITY_ID = entity_id And
                          m.PROFILE_NOTES IsNot Nothing
                           Select m.PROFILE_NOTES).First

        txtComment1.Text = profileNote
    End Sub
End Class

